package com.ybkj.daijia.api.member.v4;

import com.ybkj.daijia.server.news.NoticeNews;
import com.ybkj.daijia.server.service.NewsService;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller("NewsProcessControllerV4")
@RequestMapping(value = "passenger/api/rest/v4/news")
public class NewsProcessController {

    @Autowired
    private NewsService newsService;

    /**
     * 查询新闻.
     */
    @RequestMapping(value = "queryNews", method = RequestMethod.GET)
    public @ResponseBody
    Map<String, Object> queryNews() {
        Map<String, Object> map = new HashMap<String, Object>();
        try {
            List<Map<String, Object>> list = newsService.findNews();
            map.put("code", 0);
            map.put("data", list);
            map.put("message", "成功");
        } catch (Exception e) {
            e.printStackTrace();
            map.put("code", 500);
            map.put("message", "查询失败");
        }
        return map;
    }

    /**
     * 跳转新闻页面.
     */
    @RequestMapping(value = "news", method = RequestMethod.GET)
    public String custom(Long id, Model model) {
        NoticeNews noticeNews = newsService.findOne(id);

        model.addAttribute("title", noticeNews.getTitle());

        model.addAttribute("content", noticeNews.getContent());

        return "news/content";
    }

}
